import React, { useState, useEffect } from 'react';

import { NavBar, Icon, List, InputItem, Picker, DatePicker, TextareaItem, Button, Toast, Accordion, Modal } from 'antd-mobile';

import { Link, withRouter } from 'react-router-dom';
import { getListStudent } from "@/api/parent/chilDinformation.js"

import './studentList.scss';

function StudentList (props) {
    const [userInfoDetailsObject, setUserInfoDetailsObject] = useState({})
    const userInfo = JSON.parse(sessionStorage.getItem('userInfo'));

    let [studentList, setStudentList] = useState([]);  // 学生列表信息

    // 学生列表
    function studentListFn () {
        let list = studentList.map((item, index) => {
            return (
                <li key={index}>
                    <Link to={
                        {
                            pathname: `/studentDetails`,
                            params: item,
                        }
                    }>
                        {`${item.name}`}

                        <Icon type={'right'} />

                    </Link>
                </li>
            )
        });

        return list;
    }

    useEffect(() => {
        // 查询孩子列表信息
        getListStudent({ parent_id: userInfo.id }).then(res => {
            if (res.code == '000000') {
                setStudentList(res.responseData.dataList)
            }
        }).catch(err => {

        })
    }, [])

    return (
        <div className="resume-list">
            <div className="page-title">
                <NavBar
                    mode="light"
                    icon={<Icon type="left" />}
                    onLeftClick={() => {
                        props.history.push({
                            pathname: '/main',
                            query: {
                                selectedTab: 'my'
                            }
                        })
                    }}
                >
                    学生列表
                </NavBar>

            </div>
            <div className="page-content">
                <div className="resume-content-piece">
                    <ol>
                        {studentListFn()}
                    </ol>

                    <div className="btns">
                        <Button type="primary" onClick={() => {
                            props.history.push({
                                pathname: '/student'
                            })
                        }}>添加学生</Button>
                    </div>
                </div>
            </div>
        </div >
    );
}

export default StudentList;